# -*- encoding: utf-8 -*-
from django.db import models
from django.utils.translation import ugettext_lazy as _

from multilingual.translation import TranslationModel
from filebrowser.fields import FileBrowseField

from modulo.page.models import Section

class Sponsor(models.Model):
    section = models.ForeignKey(Section, related_name="sponsors",
                                limit_choices_to = {'app': 'sponsors'},
                                help_text=_(u"Selection de la rubrique contenant ce sponsor."))

    logo = FileBrowseField(_(u'logo'), max_length=100, directory="sponsors", format='Image', help_text=_(u"Logo du partenaire - attention de bien choisir la miniature de 140px."))
    url = models.URLField(_(u'Site internet'))

    order = models.IntegerField(editable=False, default=0)

    class Translation(TranslationModel):
        name = models.CharField(_(u'nom'), max_length=50)

    def save(self):
        if self.order == 0:
            self.order = Sponsor.objects.count()+1
        super(Sponsor, self).save()

    def get_absolute_url(self):
        return u"%s" % self.url
    
    def __unicode__(self):
        return u"%s" % self.name
